package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeliveryDetail;
import com.ruoyi.system.service.IDeliveryDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购单详情Controller
 *
 * @author ruoyi
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/deliveryDetail")
public class DeliveryDetailController extends BaseController {
    @Resource
    private IDeliveryDetailService deliveryDetailService;

    /**
     * 查询采购单详情列表
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryDetail deliveryDetail) {
        LoginUser loginUser = getLoginUser();
        if (!loginUser.getDeptId().equals(1000001L)) {
            deliveryDetail.setSchoolId(loginUser.getDeptId());
        }
        startPage();
        List<DeliveryDetail> list = deliveryDetailService.selectDeliveryDetailList(deliveryDetail);
        return getDataTable(list);
    }

    /**
     * 导出采购单详情列表
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:export')")
    @Log(title = "采购单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryDetail deliveryDetail) {
        List<DeliveryDetail> list = deliveryDetailService.selectDeliveryDetailList(deliveryDetail);
        ExcelUtil<DeliveryDetail> util = new ExcelUtil<DeliveryDetail>(DeliveryDetail.class);
        util.exportExcel(response, list, "采购单详情数据");
    }

    /**
     * 获取采购单详情详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(deliveryDetailService.selectDeliveryDetailById(id));
    }

    /**
     * 新增采购单详情
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:add')")
    @Log(title = "采购单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryDetail deliveryDetail) {
        return toAjax(deliveryDetailService.insertDeliveryDetail(deliveryDetail));
    }

    /**
     * 修改采购单详情
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:edit')")
    @Log(title = "采购单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryDetail deliveryDetail) {
        return toAjax(deliveryDetailService.updateDeliveryDetail(deliveryDetail));
    }

    /**
     * 删除采购单详情
     */
    //@PreAuthorize("@ss.hasPermi('system:deliveryDetail:remove')")
    @Log(title = "采购单详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deliveryDetailService.deleteDeliveryDetailByIds(ids));
    }
}
